package com.swak.async.persistence.mapper;

import org.springframework.beans.factory.FactoryBean;

import com.swak.async.persistence.proxy.ProxyFactory;

/**
 * 代理创建具体的 Mapper
 * 
 * @author lifeng
 * @date 2020年4月13日 下午9:52:19
 */
public class AsyncMapperFactoryBean<T> implements FactoryBean<T> {

	private Class<T> mapperInterface;

	public AsyncMapperFactoryBean() {
	}

	public AsyncMapperFactoryBean(Class<T> mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	public void setMapperInterface(Class<T> mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	@Override
	@SuppressWarnings("unchecked")
	public T getObject() throws Exception {
		return (T) ProxyFactory.newProxy(mapperInterface);
	}

	@Override
	public Class<?> getObjectType() {
		return this.mapperInterface;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}
}
